import numpy as np
import time
from functools import wraps

def fn_timer(function):
    @wraps(function)
    def function_timer(*args, **kwargs):
        t0 = time.time()
        result = function(*args, **kwargs)
        t1 = time.time()
        print("Total time running :" + str(t1 - t0)+"seconds" )
        return result
    return function_timer

@fn_timer
def shell_sort(c):
    Sedgewick = [ 929, 505, 209, 109, 41, 19, 5, 1]
    length = len(c)
    for D in Sedgewick:  #Sedgewick增量序列
        for p in range(D, length):
            Tmp = c[p]
            i = p
            while i >= D and c[i - D] > Tmp:
                c[i] = c[i - D]
                i = i - D
                c[i] = Tmp
    return c


if __name__ == '__main__':
    old = [1, 56, 84, 23, 1, 5, 78, 3, 9, 2]
    new = np.random.randint(0, 100, 100000)
    look = shell_sort(new)

# 后记： 这个竟然写了一下午，搞了三个小时，
#          1.问题是开始的时候对整个的流程还是不是很清楚
#          2.在就是，在获得增量序列的步长后，是两个两个从前往后相互比较的，不是说获取到一个
#          3.完整的序列在进行比较，或许这样也可以，但是太耗费时间了。再也是没理解透彻的点。
#          4.以后先理解透彻，再自己写，写不成再参考，完整的参考。然后重写
#for D in Sedgewick:
    # for p in range(D,length):
    #     tem = L[p]
    #     i = p - D
    #     while i >=0 and tem < L[i]:
    #         L[i+D], L[i] = L[i], L[i+D]
    #         i = i - D